package com.taptech.doufu.ui.view.userdetail

import android.content.Context
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.google.gson.Gson
import com.taptech.doufu.R
import com.taptech.doufu.model.user.ListItem
import com.taptech.doufu.model.user.NovelBean
import com.taptech.doufu.ui.activity.NovelDetailsActivity
import com.taptech.doufu.util.DiaobaoUtil
import com.taptech.doufu.util.GsonUtil
import kotlinx.android.synthetic.main.view_user_detail_latest_novel.view.*

class UserDetailLatestNovelView(context: Context):LinearLayout(context) {


    init {
        initView()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.view_user_detail_latest_novel,null)
        addView(view)
    }

    fun setData(data: ListItem) {
        try {
            val info:NovelBean = GsonUtil.parseJsonWithGson(Gson().toJson(data.data), NovelBean::class.java)
            tvUpdateTip.text = info.updateTip
            tvUpdateTime.text = DiaobaoUtil.seconds2TimeString(info.update_time)
            setOnClickListener {
                NovelDetailsActivity.startActivity(context,info.id)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }
}
